package com.atguigu.juc.locks;

import java.util.concurrent.TimeUnit;

//两部手机两个方法先打印谁
class Phone4{
    public synchronized void sengEmail(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "正在发邮件...");
    }
    public synchronized void sengSMS(){
        System.out.println(Thread.currentThread().getName() + "正在发短信...");
    }
}

public class Lock8_4 {
    public static void main(String[] args) {
        Phone4 phone4 = new Phone4();
        Phone4 phone4_2 = new Phone4();

        new Thread(()->{phone4.sengEmail();},"t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{phone4_2.sengSMS();},"t2").start();
    }
}
